package com.sgcc.dlsc.redis.demo.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisClusterConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: 李孟帅
 * @CreateTime: 2019-11-04 11:39
 * @Description: ${Description}
 */
@Component
@ConfigurationProperties(prefix = "spring.redis.cluster")
public class RedisClusterConfig {

    private List<String> nodes;

    public void setNodes(List<String> nodes) {
       this.nodes=nodes;

    }

    @Bean
    public RedisClusterConnection getRedisClusterConnection(){
        JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(new RedisClusterConfiguration(nodes));
        jedisConnectionFactory.afterPropertiesSet();
        return jedisConnectionFactory.getClusterConnection();
    }

}
